package com.xnyzc.lhy.order.entity.util;

import com.xnyzc.lhy.common.constant.MessageConstant;
import com.xnyzc.lhy.common.penum.EOrderType;
import com.xnyzc.lhy.common.penum.pay.ETransactionOrderNoType;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: huxuekuo
 * @Date: 2019-07-23 15:52
 * @Description:
 */
public class OrderUtil {

    /**
     * 订单类型
     *
     * @param carPool 0 - 专车 1- 拼车
     * @return
     */
    public static String orderType(int carPool) {
        if (carPool == 0) {
            return MessageConstant.ORDER_TYPE_ONE;
        } else {
            return MessageConstant.ORDER_TYPE_TWO;
        }
    }

    public static String carpoolNo() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        //当前时间
        String date = simpleDateFormat.format(new Date());
        //当前类型
        String orderType = EOrderType.BKCP.getValue();
        long s = (long) ((Math.random() * 9 + 1) * 100000000);
        return orderType + date + s;
    }

    /**
     * 预约类型
     *
     * @param time 预约时间
     * @return
     */
    public static String resrvationType(Date time) {
        if (null == time) {
            return MessageConstant.ORDER_RESRVATION_ONE;
        } else {
            return MessageConstant.ORDER_RESRVATION_TWO;
        }
    }

    /**
     * 获取订单ID
     *
     * @param eOrderType 订单类型
     * @return
     */
    public static String orderNo(EOrderType eOrderType) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        //当前时间
        String date = simpleDateFormat.format(new Date());
        //当前类型
        String orderType = eOrderType.getValue();
        long s = (long) ((Math.random() * 9 + 1) * 100000000);
        return orderType + date + s;
    }

    /**
     * 获取流水
     *
     * @param eTransactionOrderNoType 订单类型
     * @return
     */
    public static String transactionOrderNo(ETransactionOrderNoType eTransactionOrderNoType) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        //当前时间
        String date = simpleDateFormat.format(new Date());
        //当前类型
        String no = eTransactionOrderNoType.getNo();
        long s = (long) ((Math.random() * 9 + 1) * 100000000);
        return no + date + s;
    }

    public static EOrderType orderCallType(int type) {
        if (0 == type) {
            return EOrderType.ZFJC;
        } else if (1 == type) {
            return EOrderType.GRGW;
        } else if (2 == type) {
            return EOrderType.BMGW;
        } else if (3 == type) {
            return EOrderType.SPGW;
        }
        return null;
    }
}
